/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aulagrafos;

import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseGraph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.ArrayList;
import javax.swing.JFrame;

/**
 *
 * @author Alexandre.silva10
 */
public class View {
    
    public View(int ga[][]) {
        g = new SparseMultigraph<String, String>();
        ArrayList<Integer> visitados = new ArrayList<>();
        for (int i = 0; i < 500; i++) {
            for (int j = 0; j < 500; j++) {
                if (ga[i][j] != -1) {
                    if (!visitados.contains(i)) {
                        g.addVertex(Integer.toString(i));
                    }
                    if (!visitados.contains(j)) {
                        g.addVertex(Integer.toString(j));
                    }
                    if(ga[i][j] != 0)
                        g.addEdge(Integer.toString(ga[i][j]), Integer.toString(i), Integer.toString(j));
                }
            }
        }
    }
    
    public static void run(int ga[][]) {
        //fazendo a magica
        View sgv = new View(ga); // Creates the graph...
        // Layout<V, E>, VisualizationComponent<V,E>
        Layout<String, String> layout = new CircleLayout(sgv.g);
        layout.setSize(new Dimension(500, 500));
        VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(layout);
        vv.setPreferredSize(new Dimension(700, 700));
        // Show vertex and edge labels
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());

        // Create a graph mouse and add it to the visualization component
        DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
        gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
        vv.setGraphMouse(gm);
        JFrame frame = new JFrame("Visualização do Grafo");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(vv);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setResizable(false);
        frame.setVisible(true);
    }
    private Graph g;
}
